package com.cjhstudy.mall.listener;

import com.cjhstudy.mall.pojo.PayInfo;
import com.cjhstudy.mall.service.IOrderService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: phil
 * 关于 PayInfo ,正确姿势：pay项目提供client.jar, mall项目引入jar包
 * 《SpringCloud微服务实战》
 * @ProjectName: mall
 * @Date: 2021/12/11
 */
@Component
@RabbitListener(queues = "payNotify")
@Slf4j
public class PayMsgListener {

    @Autowired
    private IOrderService orderService;

    @RabbitHandler
    public void process(String msg){
        log.info("[接受到的消息] => {}",msg);

        PayInfo payInfo = new Gson().fromJson(msg, PayInfo.class);
        if (payInfo.getPlatformStatus().equals("SUCCESS")){
            //修改订单里的转态
            orderService.paid(payInfo.getOrderNo());
        }

    }
}
